#include "Board.h"
#include <stdio.h>

Field getField(Board *pBoard, int x, int y) {
	return pBoard->fieldArr[x + 4*y];
}

void setField(Board *pBoard, int x, int y, state state) {
	pBoard->fieldArr[x + 4*y].state = state;
	pBoard->fieldArr[x + 4*y].x = x;
	pBoard->fieldArr[x + 4*y].y = y;
}

void drawBoard(Board *pBoard) {
	int i,j;
	Field field;
	for(i = 0; i < 8; i++){
		
		for(j = 0; j < 4; j++) {
			field = getField(pBoard, j, i);
			drawField(&field);
		}
		printf("\n");
	}
}

Board emptyBoard() {
	Board board;
	int i,j;
	for(i = 0; i < 8; i++)
		
		for(j = 0; j < 4; j++) 
			setField(&board,j,i,STATE_EMPTY);
		
	return board;
}

void initialBlackCheckers(Board *pBoard) {
	setField(pBoard, 0,7,STATE_BLACK);
	setField(pBoard, 1,7,STATE_BLACK);
	setField(pBoard, 2,7,STATE_BLACK);
	setField(pBoard, 3,7,STATE_BLACK);
	setField(pBoard, 0,6,STATE_BLACK);
	setField(pBoard, 1,6,STATE_BLACK);
	setField(pBoard, 2,6,STATE_BLACK);
	setField(pBoard, 3,6,STATE_BLACK);
	setField(pBoard, 0,5,STATE_BLACK);
	setField(pBoard, 1,5,STATE_BLACK);
	setField(pBoard, 2,5,STATE_BLACK);
	setField(pBoard, 3,5,STATE_BLACK);
}

void initialWhiteCheckers(Board *pBoard) {
	setField(pBoard, 0,0,STATE_WHITE);
	setField(pBoard, 1,0,STATE_WHITE);
	setField(pBoard, 2,0,STATE_WHITE);
	setField(pBoard, 3,0,STATE_WHITE);
	setField(pBoard, 0,1,STATE_WHITE);
	setField(pBoard, 1,1,STATE_WHITE);
	setField(pBoard, 2,1,STATE_WHITE);
	setField(pBoard, 3,1,STATE_WHITE);
	setField(pBoard, 0,2,STATE_WHITE);
	setField(pBoard, 1,2,STATE_WHITE);
	setField(pBoard, 2,2,STATE_WHITE);
	setField(pBoard, 3,2,STATE_WHITE);
}
